package util
{

	import flash.display.BitmapData;
	import flash.filters.GlowFilter;

	import globals.ButtonType;
	import globals.Global;

	import ui.component.Button;
	import ui.component.ImageButton;
	import ui.component.TextButton;

	public class UIUtil
	{
		/////////////按钮的状态背景///////////////
		private static var defaultBtmd:BitmapData;
		private static var overBtmd:BitmapData;
		private static var downBtmd:BitmapData;
		private static var disableBtmd:BitmapData;
		////////////end 按钮的状态背景/////////////
		private static var btnTextFilter:GlowFilter;

		/**获取带有文字的按钮**/
		public static function getTextButton(id:int = 0, text:String = '', type:int = ButtonType.BUTTON_BLUE, clickHandle:Function = null):TextButton
		{
			var button:TextButton;
			updateBottonSkin(type);
			button = new TextButton(text, defaultBtmd, overBtmd, downBtmd, disableBtmd);
			button.id = id;
			button.clickCallback = clickHandle;

			if(btnTextFilter != null)
			{
				button.getLabel().filters = [btnTextFilter];
			}
			else
			{
				button.getLabel().filters = [];
			}
			return button;
		}

		/**获取纯的按钮**/
		public static function getButton(id:int = 0, type:int = ButtonType.BUTTON_BLUE, clickHandle:Function = null):Button
		{
			var button:Button;
			updateBottonSkin(type);
			button = new Button(defaultBtmd, overBtmd, downBtmd, disableBtmd);
			button.id = id;
			button.clickCallback = clickHandle;
			return button;
		}

		private static function updateBottonSkin(type:int):void
		{
			defaultBtmd = null;
			overBtmd = null;
			downBtmd = null;
			disableBtmd = null;
			btnTextFilter = null;

			switch(type)
			{
				case ButtonType.BUTTON_PANEL_CLOSE:
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("button_panelClose_default", "ui");
					overBtmd = Global.assetsManager.getAssetsAsBitmapData("button_panelClose_over", "ui");
					downBtmd = Global.assetsManager.getAssetsAsBitmapData("button_panelClose_down", "ui");
					break;
				case ButtonType.BUTTON_BLUE: //正常的蓝色按钮类型
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("button_blue_default", "ui");
					overBtmd = Global.assetsManager.getAssetsAsBitmapData("button_blue_over", "ui");
					downBtmd = Global.assetsManager.getAssetsAsBitmapData("button_blue_down", "ui");
					disableBtmd = Global.assetsManager.getAssetsAsBitmapData("button_blue_disable", "ui");
					btnTextFilter = TextStyle.getButtonTextFilter(0x044764);
					break;
				case ButtonType.BUTTON_GREEN: //正常的绿色按钮类型
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("button_green_default", "ui");
					overBtmd = Global.assetsManager.getAssetsAsBitmapData("button_green_over", "ui");
					downBtmd = Global.assetsManager.getAssetsAsBitmapData("button_green_down", "ui");
					disableBtmd = Global.assetsManager.getAssetsAsBitmapData("button_green_disable", "ui");
					btnTextFilter = TextStyle.getButtonTextFilter(0x355900);
					break;
				case ButtonType.BUTTON_YELLOW: //正常的黄色按钮类型
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("button_yellow_default", "ui");
					overBtmd = Global.assetsManager.getAssetsAsBitmapData("button_yellow_over", "ui");
					downBtmd = Global.assetsManager.getAssetsAsBitmapData("button_yellow_down", "ui");
					disableBtmd = Global.assetsManager.getAssetsAsBitmapData("button_yellow_disable", "ui");
					btnTextFilter = TextStyle.getButtonTextFilter(0x653011);
					break;
				case ButtonType.BUTTON_BLUE_HEIGHT: //高的蓝色按钮类型
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("button_blueHeight_default", "ui");
					overBtmd = Global.assetsManager.getAssetsAsBitmapData("button_blueHeight_over", "ui");
					downBtmd = Global.assetsManager.getAssetsAsBitmapData("button_blueHeight_down", "ui");
					disableBtmd = Global.assetsManager.getAssetsAsBitmapData("button_blueHeight_disable", "ui");
					btnTextFilter = TextStyle.getButtonTextFilter(0x044764);
					break;
				case ButtonType.BUTTON_GREEN_HEIGHT: //高的绿色按钮类型
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("button_greenHeight_default", "ui");
					overBtmd = Global.assetsManager.getAssetsAsBitmapData("button_greenHeight_over", "ui");
					downBtmd = Global.assetsManager.getAssetsAsBitmapData("button_greenHeight_down", "ui");
					disableBtmd = Global.assetsManager.getAssetsAsBitmapData("button_greenHeight_disable", "ui");
					btnTextFilter = TextStyle.getButtonTextFilter(0x355900);
					break;
				case ButtonType.BUTTON_GREEN_SMALL: //小的绿色按钮类型
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("button_greenSmall_default", "ui");
					overBtmd = Global.assetsManager.getAssetsAsBitmapData("button_greenSmall_over", "ui");
					downBtmd = Global.assetsManager.getAssetsAsBitmapData("button_greenSmall_down", "ui");
					disableBtmd = Global.assetsManager.getAssetsAsBitmapData("button_greenSmall_disable", "ui");
					btnTextFilter = TextStyle.getButtonTextFilter(0x355900);
					break;
				case ButtonType.BUTTON_LIST: //列表按钮类型（英雄选择时）
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("button_list_default", "ui");
					overBtmd = Global.assetsManager.getAssetsAsBitmapData("button_list_over", "ui");
					break;
				case ButtonType.BUTTON_ARROW_LEFT: //左箭头
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("arrow_l_default", "ui");
					overBtmd = Global.assetsManager.getAssetsAsBitmapData("arrow_l_over", "ui");
					downBtmd = Global.assetsManager.getAssetsAsBitmapData("arrow_l_down", "ui");
					break;
				case ButtonType.BUTTON_ARROW_RIGHT: //右箭头
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("arrow_r_default", "ui");
					overBtmd = Global.assetsManager.getAssetsAsBitmapData("arrow_r_over", "ui");
					downBtmd = Global.assetsManager.getAssetsAsBitmapData("arrow_r_down", "ui");
					break;
				case ButtonType.BUTTON_MENU_TAB: //面板菜单
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("tab_off", "ui");
					//overBtmd = Global.assetsManager.getAssetsAsBitmapData("tab_off", "ui");
					break;
				case ButtonType.BUTTON_PAGE: //页码
					//只用显示文字，不用背景图，所以全是null值。
					btnTextFilter = TextStyle.getButtonTextFilter(0x653011);
					break;
				case ButtonType.BUTTON_ADD:
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("button_add_default", "ui");
					overBtmd = Global.assetsManager.getAssetsAsBitmapData("button_add_over", "ui");
					downBtmd = Global.assetsManager.getAssetsAsBitmapData("button_add_down", "ui");
					disableBtmd = Global.assetsManager.getAssetsAsBitmapData("button_add_disable", "ui");
					break;
				case ButtonType.BUTTON_ARROW_2_LEFT: //左箭头
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("arrow_L_2_default", "ui");
					overBtmd = Global.assetsManager.getAssetsAsBitmapData("arrow_L_2_over", "ui");
					downBtmd = Global.assetsManager.getAssetsAsBitmapData("arrow_L_2_down", "ui");
					break;
				case ButtonType.BUTTON_ARROW_2_RIGHT: //右箭头
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("arrow_R_2_default", "ui");
					overBtmd = Global.assetsManager.getAssetsAsBitmapData("arrow_R_2_over", "ui");
					downBtmd = Global.assetsManager.getAssetsAsBitmapData("arrow_R_2_down", "ui");
					break;
				case ButtonType.BUTTON_YELLOW_SMALL: //小的黄色按钮
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("button_yellowSmall_default", "ui");
					overBtmd = Global.assetsManager.getAssetsAsBitmapData("button_yellowSmall_over", "ui");
					downBtmd = Global.assetsManager.getAssetsAsBitmapData("button_yellowSmall_down", "ui");
					btnTextFilter = TextStyle.getButtonTextFilter(0x000000);
					break;
				case ButtonType.BUTTON_REFRESH: //刷新按钮
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("button_refresh_default", "ui");
					overBtmd = Global.assetsManager.getAssetsAsBitmapData("button_refresh_over", "ui");
					downBtmd = Global.assetsManager.getAssetsAsBitmapData("button_refresh_down", "ui");
					break;
				default:
					defaultBtmd = Global.assetsManager.getAssetsAsBitmapData("button_blue_default", "ui");
					overBtmd = Global.assetsManager.getAssetsAsBitmapData("button_blue_over", "ui");
					downBtmd = Global.assetsManager.getAssetsAsBitmapData("button_blue_down", "ui");
					disableBtmd = Global.assetsManager.getAssetsAsBitmapData("button_blue_disable", "ui");
					btnTextFilter = TextStyle.getButtonTextFilter(0x044764);
					break;
			}
		}

		public static function getImageButton(imageUrl:String, keys:Array, handler:Function = null):ImageButton
		{
			var button:ImageButton = new ImageButton(imageUrl, Global.assetsManager.getAssetsAsBitmapData(keys[0]), Global.assetsManager.getAssetsAsBitmapData(keys[1]),
				Global.assetsManager.getAssetsAsBitmapData(keys[2]), null, handler);
			return button;
		}
	}
}